<template>
  <div>
    <!-- 头导航 -->
    <div>
      <van-nav-bar title="搜索" left-text="返回" left-arrow>
        <template #right>
          <van-icon name="search" @click="search" size="18" />
        </template>
      </van-nav-bar>
      <van-overlay :show="isShow">
        <div class="wrapper">
          <!-- 搜素框 -->
          <div class="searchBox">
            <form action="/">
              <van-search
                v-model="value"
                show-action
                placeholder="请输入搜索关键词"
                @search="onSearch"
                @cancel="onCancel"
              />
            </form>
          </div>
        </div>
      </van-overlay>
    </div>

    <!-- 轮播图 -->
    <!-- Swiper -->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="(item, index) in list"
          :key="index"
          @click="go"
        >
          <div class="imgCon">
            <img :src="item" alt="" />
          </div>
          <span class="text">美食</span>
        </div>
      </div>
    </div>

    <!-- 商品卡片 -->
    <div v-for="(item, index) in shopInfo" :key="index">
      <van-card @click="goDetail(item)">
        <template #thumb>
          <div>

            <img :src="item.info.goodsimg" alt="">
          </div>
        </template>
        <template #desc>
          <!-- 商家名字 -->
          <div class="shopName">
            {{ item.info.name }}
          </div>
          <!-- 评价 -->
          <div>评价{{ item.info.score }}月售{{ item.info.sellCount }}</div>
          <!--  -->
          <div>起送￥{{ item.info.minPrice }}配送￥{{ item.info.deliveryPrice }}</div>
        </template>
        <template #num>
          <div>{{ item.info.deliveryTime }}分钟{{ item.info.distance }}</div>
        </template>
      </van-card>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import uri from "@/config/uri";
import { Toast, NavBar, Overlay, Search, Card } from "vant";
import Swiper from "swiper";
import "swiper/swiper-bundle.min.css";

import b from "@/assets/swiperIcon/b.png";
import a from "@/assets/swiperIcon/a.png";
import c from "@/assets/swiperIcon/c.png";
import d from "@/assets/swiperIcon/d.png";
import e from "@/assets/swiperIcon/e.png";
import f from "@/assets/swiperIcon/f.png";
Vue.use(NavBar);
Vue.use(Overlay);
Vue.use(Search);
Vue.use(Card);
export default {
  data() {
    return {
      isShow: false,
      /* 搜索 */
      value: "",
      /* 商家数据 */
      shopInfo: [],
      shopDetail: [],
      // 轮播图片
      list: [a, b, c, d, e, f, b, a, c, d, e, f, a, b, c, d],
    };
  },
  created() {
    this.$http.get(uri.shopInfo).then((res) => {
      console.log(uri.shopInfo);
      console.log(res)
      res.map((item, index) => {
        this.shopInfo.push(item);
        // this.shopDetail.push(item.goods)
        return this.shopInfo;
      });
    });
    this.$nextTick(() => {
      new Swiper(".swiper-container", {
        slidesPerView: 3,
        slidesPerColumn: 2,
        spaceBetween: 30,
      });

      // 创建实例时会根据有多少数据将每个的宽度预留好，但因为循环需要时间，因此需要通过this.$nextTick
    });
  },
  methods: {
    goDetail(item) {
      console.log(item);
      localStorage.setItem("shopDetail",JSON.stringify(item))
      this.$router.push("/detail/"+item.info.name)
    },
    onClickLeft() {
      Toast("返回");
    },
    onClickRight() {
      Toast("按钮");
    },
    /* 搜索按钮 */
    search() {
      this.isShow = true;
    },
    /* 搜索 */
    onSearch(val) {
      Toast(val);
    },
    onCancel() {
      this.isShow = false;
    },
    // 轮播图点击事件
    go() {},
  },
};
</script>
<style scoped>
/* 遮罩层 */
.van-nav-bar__content {
  background-color: #03a774;
  color: white;
}
.wrapper {
  display: flex;
  height: 100%;
  width: 100%;
}
.searchBox {
  width: 100%;
}

img {
  width: 50px;
  height: 50px;
  display: block;
  margin: 0 auto;
}
html,
body {
  position: relative;
  height: 100%;
}

body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}

.text {
  width: 40px !important;
  height: 40px;
  font-size: 14px;
}
.swiper-container {
  width: 100%;
  height: 100%;
  margin-left: auto;
  margin-right: auto;
}
.swiper-wrapper {
  width: 100%;
  height: 200px;
}
.swiper-slide {
  text-align: center;
  font-size: 18px;
  /* background: pink; */
  height: calc((100% - 30px) / 2);

  /* Center slide text vertically */
  /* text-align: center; */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: block;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}
</style>